<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id
	
	+ Module  		: t_add Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_t_add.php
 	+ creator 		: 
 	+ Created on 24/Jul/2012 10:52:52
	
*/

//class of t_add
class C_t_add extends CI_Controller {

	//constructor
	function __construct(){
		parent::__construct();
		
		$this->load->model('m_t_add', '', TRUE);
		checkLogin();
	}
	
	function adddet_list(){
		$kontrak_no = isset($_POST['kontrak_no']) ? @$_POST['kontrak_no'] : "";
		$add_id = isset($_POST['add_id']) ? @$_POST['add_id'] : "";
		$result=$this->m_t_add->adddet_list($kontrak_no,$add_id);
		echo $result;
	}
	
	function get_jobdet_all(){
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_t_add->get_jobdet_all($query, $start, $end);
		echo $result;
	}
	
	//set index
	function index(){
		$this->load->view('main/v_t_add');
	}
	
	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "LIST":
				$this->t_add_list();
				break;
			case "UPDATE":
				$this->t_add_update();
				break;
			case "CREATE":
				$this->t_add_create();
				break;
			case "DELETE":
				$this->t_add_delete();
				break;
			case "SEARCH":
				$this->t_add_search();
				break;
			case "PRINT":
				$this->t_add_print();
				break;
			case "EXCEL":
				$this->t_add_export_excel();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	//function fot list record
	function t_add_list(){
		
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_t_add->t_add_list($query,$start,$end);
		echo $result;
	}
	
	//function for create new record
	function t_add_create(){
		//POST varible here
		//auto increment, don't accept anything from form values
		$add_kontrak=trim(@$_POST["add_kontrak"]);
		$add_kontrak=is_numeric($add_kontrak)?$add_kontrak:0;
		$add_type=trim(@$_POST["add_type"]);
		$add_seq=trim(@$_POST["add_seq"]);
		$add_req_date=@$_POST["add_req_date"];
		$add_req_date=date(LONG_FORMATDATE, strtotime($add_req_date));
		$add_req_no=trim(@$_POST["add_req_no"]);
		$add_acc_date=@$_POST["add_acc_date"];
		$add_acc_date=date(LONG_FORMATDATE, strtotime($add_acc_date));
		$add_acc_no=trim(@$_POST["add_acc_no"]);
		$add_date=@$_POST["add_date"];
		$add_date=date(LONG_FORMATDATE, strtotime($add_date));
		$add_no=trim(@$_POST["add_no"]);
		$add_begin_date=@$_POST["add_begin_date"];
		$add_begin_date=date(LONG_FORMATDATE, strtotime($add_begin_date));
		$add_end_date=@$_POST["add_end_date"];
		$add_end_date=date(LONG_FORMATDATE, strtotime($add_end_date));
		$add_value=trim(@$_POST["add_value"]);
		$add_value=is_numeric($add_value)?$add_value:0;
		//data detail
		$array_adddet_id=@$_POST["adddet_id"];
		$array_adddet_id=json_decode(stripslashes($array_adddet_id));
		$array_badet_id=@$_POST["badet_id"];
		$array_badet_id=json_decode(stripslashes($array_badet_id));
		$array_jobdet_id=@$_POST["jobdet_id"];
		$array_jobdet_id=json_decode(stripslashes($array_jobdet_id));
		$array_volume=@$_POST["volume"];
		$array_volume=json_decode(stripslashes($array_volume));
		$array_unit_id=@$_POST["unit_id"];
		$array_unit_id=json_decode(stripslashes($array_unit_id));
		$array_adddet_price=@$_POST["adddet_price"];
		$array_adddet_price=json_decode(stripslashes($array_adddet_price));
		
		$result=$this->m_t_add->t_add_create($add_kontrak, $add_type, $add_seq, $add_req_date, $add_req_no, $add_acc_date, $add_acc_no, $add_date, $add_no, 
				$add_begin_date, $add_end_date, $add_value,
				$array_adddet_id, $array_badet_id, $array_jobdet_id, $array_volume, $array_unit_id, $array_adddet_price);
		echo $result;
	}
	
	
	//function for update record
	function t_add_update(){
		//POST variable here
		$add_id=trim(@$_POST["add_id"]);
		$add_id=is_numeric($add_id)?$add_id:0;
		$add_kontrak=trim(@$_POST["add_kontrak"]);
		$add_kontrak=is_numeric($add_kontrak)?$add_kontrak:0;
		$add_type=trim(@$_POST["add_type"]);
		$add_seq=trim(@$_POST["add_seq"]);
		$add_req_date=@$_POST["add_req_date"];
		$add_req_date=date(LONG_FORMATDATE, strtotime($add_req_date));
		$add_req_no=trim(@$_POST["add_req_no"]);
		$add_acc_date=@$_POST["add_acc_date"];
		$add_acc_date=date(LONG_FORMATDATE, strtotime($add_acc_date));
		$add_acc_no=trim(@$_POST["add_acc_no"]);
		$add_date=@$_POST["add_date"];
		$add_date=date(LONG_FORMATDATE, strtotime($add_date));
		$add_no=trim(@$_POST["add_no"]);
		$add_begin_date=@$_POST["add_begin_date"];
		$add_begin_date=date(LONG_FORMATDATE, strtotime($add_begin_date));
		$add_end_date=@$_POST["add_end_date"];
		$add_end_date=date(LONG_FORMATDATE, strtotime($add_end_date));
		$add_value=trim(@$_POST["add_value"]);
		$add_value=is_numeric($add_value)?$add_value:0;
		//data detail
		$array_adddet_id=@$_POST["adddet_id"];
		$array_adddet_id=json_decode(stripslashes($array_adddet_id));
		$array_badet_id=@$_POST["badet_id"];
		$array_badet_id=json_decode(stripslashes($array_badet_id));
		$array_jobdet_id=@$_POST["jobdet_id"];
		$array_jobdet_id=json_decode(stripslashes($array_jobdet_id));
		$array_volume=@$_POST["volume"];
		$array_volume=json_decode(stripslashes($array_volume));
		$array_unit_id=@$_POST["unit_id"];
		$array_unit_id=json_decode(stripslashes($array_unit_id));
		$array_adddet_price=@$_POST["adddet_price"];
		$array_adddet_price=json_decode(stripslashes($array_adddet_price));
		
		$result=$this->m_t_add->t_add_update($add_id, $add_kontrak, $add_type, $add_seq, $add_req_date, $add_req_no, $add_acc_date, $add_acc_no, $add_date, $add_no, 
				$add_begin_date, $add_end_date, $add_value,
				$array_adddet_id, $array_badet_id, $array_jobdet_id, $array_volume, $array_unit_id, $array_adddet_price);
		echo $result;
	}
	
	//function for delete selected record
	function t_add_delete(){
		$ids = @$_POST['ids']; // Get our array back and translate it :
		$pkid = json_decode(stripslashes($ids));
		$result=$this->m_t_add->t_add_delete($pkid);
		echo $result;
	}

	//function for advanced search
	function t_add_search(){
		//POST varibale here
		$add_id=@$_POST["add_id"];
		$add_id=is_numeric($add_id)?$add_id:0;
		$add_flag=trim(@$_POST["add_flag"]);
		$add_flag=htmlentities($add_flag,ENT_QUOTES);
		$job=trim(@$_POST["job"]);
		$job=htmlentities($job,ENT_QUOTES);
		$project=trim(@$_POST["project"]);
		$project=htmlentities($project,ENT_QUOTES);
		$add_name=trim(@$_POST["add_name"]);
		$add_name=htmlentities($add_name,ENT_QUOTES);
		$add_shortname=trim(@$_POST["add_shortname"]);
		$add_shortname=htmlentities($add_shortname,ENT_QUOTES);
		$add_pm=trim(@$_POST["add_pm"]);
		$add_pm=htmlentities($add_pm,ENT_QUOTES);
		$add_semcm=trim(@$_POST["add_semcm"]);
		$add_semcm=htmlentities($add_semcm,ENT_QUOTES);
		$add_value=trim(@$_POST["add_value"]);
		$add_start=trim(@$_POST["add_start"]);
		$add_p1=trim(@$_POST["add_p1"]);
		$add_p2=trim(@$_POST["add_p2"]);
		$add_created_date=trim(@$_POST["add_created_date"]);
		$add_created_by=trim(@$_POST["add_created_by"]);
		$add_created_by=htmlentities($add_created_by,ENT_QUOTES);
		$add_updated_date=trim(@$_POST["add_updated_date"]);
		$add_updated_by=trim(@$_POST["add_updated_by"]);
		$add_updated_by=htmlentities($add_updated_by,ENT_QUOTES);
		$add_updated_count=@$_POST["add_updated_count"];
		$add_updated_count=is_numeric($add_updated_count)?$add_updated_count:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		
		$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
		$result = $this->m_t_add->t_add_search($add_id ,$add_flag ,$job ,$project ,$add_name ,$add_shortname ,$add_pm ,$add_semcm ,$add_value ,$add_start ,$add_p1 ,$add_p2 ,$add_created_date ,$add_created_by ,$add_updated_date ,$add_updated_by ,$add_updated_count ,$branch ,$start,$end);
		echo $result;
	}


	function t_add_print(){
  		//POST varibale here
		$add_id=@$_POST["add_id"];
		$add_id=is_numeric($add_id)?$add_id:0;
		$add_flag=trim(@$_POST["add_flag"]);
		$add_flag=htmlentities($add_flag,ENT_QUOTES);
		$job=trim(@$_POST["job"]);
		$job=htmlentities($job,ENT_QUOTES);
		$project=trim(@$_POST["project"]);
		$project=htmlentities($project,ENT_QUOTES);
		$add_name=trim(@$_POST["add_name"]);
		$add_name=htmlentities($add_name,ENT_QUOTES);
		$add_shortname=trim(@$_POST["add_shortname"]);
		$add_shortname=htmlentities($add_shortname,ENT_QUOTES);
		$add_pm=trim(@$_POST["add_pm"]);
		$add_pm=htmlentities($add_pm,ENT_QUOTES);
		$add_semcm=trim(@$_POST["add_semcm"]);
		$add_semcm=htmlentities($add_semcm,ENT_QUOTES);
		$add_value=trim(@$_POST["add_value"]);
		$add_start=trim(@$_POST["add_start"]);
		$add_p1=trim(@$_POST["add_p1"]);
		$add_p2=trim(@$_POST["add_p2"]);
		$add_created_date=trim(@$_POST["add_created_date"]);
		$add_created_by=trim(@$_POST["add_created_by"]);
		$add_created_by=htmlentities($add_created_by,ENT_QUOTES);
		$add_updated_date=trim(@$_POST["add_updated_date"]);
		$add_updated_by=trim(@$_POST["add_updated_by"]);
		$add_updated_by=htmlentities($add_updated_by,ENT_QUOTES);
		$add_updated_count=@$_POST["add_updated_count"];
		$add_updated_count=is_numeric($add_updated_count)?$add_updated_count:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$data["data_print"] = $this->m_t_add->t_add_print($add_id ,$add_flag ,$job ,$project ,$add_name ,$add_shortname ,$add_pm ,$add_semcm ,$add_value ,$add_start ,$add_p1 ,$add_p2 ,$add_created_date ,$add_created_by ,$add_updated_date ,$add_updated_by ,$add_updated_count ,$branch ,$option,$filter);
		$print_view=$this->load->view("main/p_t_add.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_add_printlist.html","w+");
		fwrite($print_file, $print_view);
		echo '1';        
	}
	/* End Of Function */

	/* Function to Export Excel document */
	function t_add_export_excel(){
		//POST varibale here
		$add_id=@$_POST["add_id"];
		$add_id=is_numeric($add_id)?$add_id:0;
		$add_flag=trim(@$_POST["add_flag"]);
		$add_flag=htmlentities($add_flag,ENT_QUOTES);
		$job=trim(@$_POST["job"]);
		$job=htmlentities($job,ENT_QUOTES);
		$project=trim(@$_POST["project"]);
		$project=htmlentities($project,ENT_QUOTES);
		$add_name=trim(@$_POST["add_name"]);
		$add_name=htmlentities($add_name,ENT_QUOTES);
		$add_shortname=trim(@$_POST["add_shortname"]);
		$add_shortname=htmlentities($add_shortname,ENT_QUOTES);
		$add_pm=trim(@$_POST["add_pm"]);
		$add_pm=htmlentities($add_pm,ENT_QUOTES);
		$add_semcm=trim(@$_POST["add_semcm"]);
		$add_semcm=htmlentities($add_semcm,ENT_QUOTES);
		$add_value=trim(@$_POST["add_value"]);
		$add_start=trim(@$_POST["add_start"]);
		$add_p1=trim(@$_POST["add_p1"]);
		$add_p2=trim(@$_POST["add_p2"]);
		$add_created_date=trim(@$_POST["add_created_date"]);
		$add_created_by=trim(@$_POST["add_created_by"]);
		$add_created_by=htmlentities($add_created_by,ENT_QUOTES);
		$add_updated_date=trim(@$_POST["add_updated_date"]);
		$add_updated_by=trim(@$_POST["add_updated_by"]);
		$add_updated_by=htmlentities($add_updated_by,ENT_QUOTES);
		$add_updated_count=@$_POST["add_updated_count"];
		$add_updated_count=is_numeric($add_updated_count)?$add_updated_count:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		$data["type"]="excel";
		$data["data_print"] = $this->m_t_add->t_add_print($add_id ,$add_flag ,$job ,$project ,$add_name ,$add_shortname ,$add_pm ,$add_semcm ,$add_value ,$add_start ,$add_p1 ,$add_p2 ,$add_created_date ,$add_created_by ,$add_updated_date ,$add_updated_by ,$add_updated_count ,$branch ,$option,$filter);
		$print_view=$this->load->view("main/p_t_add.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_add_printlist.xls","w+");
		fwrite($print_file, $print_view);
		echo '1';   
			
	}
	
}
?>